package com.wn.controller;

import com.wn.annotation.RequireRoles;
import com.wn.entity.Requirement;
import com.wn.service.RequirementService;
import com.wn.utils.PageParam;
import com.wn.utils.Rsp;
import com.wn.utils.SystemControllerLog;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (Requirement)表控制层
 *
 * @author makejava
 * @since 2020-10-31 15:01:43
 */
@RestController
@RequestMapping("requirement")
public class RequirementController {
    /**
     * 服务对象
     */
    @Resource
    private RequirementService requirementService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Requirement selectOne(String id) {
        return this.requirementService.queryById(id);
    }

    @SystemControllerLog(description = "分页查询需求信息")
    @PostMapping("/searchSomeRequirementByPage")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    public Rsp searchSomeByPage(@RequestBody PageParam<Requirement> requirementPageParam,@RequestHeader("token") String token){
        return Rsp.success(requirementService.queryAllByLimit(requirementPageParam));
    }

    @SystemControllerLog(description = "添加需求信息")
    @PostMapping("/addOneRequirement")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    public Rsp addOne(@RequestBody @Valid Requirement requirement,@RequestHeader("token") String token){
        System.out.println(requirement);
        return requirementService.insert(requirement);
    }

    @SystemControllerLog(description = "逻辑删除需求信息")
    @RequireRoles(roles = {"admin","super_admin","reception"},index = 1)
    @PostMapping("/deleteRequirementLogical")
    public Rsp deleteUserLogical(@RequestBody Requirement requirement,@RequestHeader("token") String token){

        return requirementService.deleteLogical(requirement);
    }


    @RequireRoles(roles = {"admin","super_admin","reception"},index = 1)
    @PostMapping("/updateRequirement")
    public Rsp updateUser(@RequestBody Requirement requirement,@RequestHeader("token") String token){

        return requirementService.update(requirement);
    }

}
